<template>
  <div class="mall-wrapper">
    <!-- 功能列表区域 -->
    <section class="feature-list" v-if="$route.name !== 'SafetyHelmet'">
      <div class="feature-item" v-for="(item, index) in featureList" :key="index" @click="goToDetail(item)">
        <div class="image-container">
          <img :src="item.headImageUrl" alt="功能图示" class="feature-img">
          <div class="type-label">{{ item.type }}</div>
        </div>
        <div class="item-content">
          <div class="title-container">
            <span class="icon">
              <img :src="item.logo" style="width: 100%;height: 100%" />
            </span>
            <h4>{{ item.name }}</h4>
          </div>
          <p class="desc-truncate">{{ item.description }}</p>
        </div>
      </div>
    </section>
    <!-- 子路由出口 -->
    <router-view/>
  </div>
</template>

<script>
import {algorithmInfoListPageVoUsingPost} from '@/api/front/apIsuanfa';

export default {
  name: 'AlgorithmMall',
  data() {
    return {
      activeSearchQuery: '', // 活动搜索关键词
      featureList: [],
      currentPage: 1,
      total: 0,
      itemsPerPage: 12 // 每页显示12个项目
    }
  },
  methods: {
    goToDetail(item) {
      this.$router.push({path: `/algorithmInfo/${item.algorithmId}`});

    },
    getList(current = 1) {
      const page = {
        size: 12,
        current: current,
      }
      algorithmInfoListPageVoUsingPost({
        body: {
          page: page,
          name: this.activeSearchQuery,
        }
      }).then(res => {
        if (res.success === true) {
          this.featureList = res.data.records;
          this.currentPage = res.data.current;
          this.itemsPerPage = res.data.size;
          this.total = res.data.total;
        }
      })
    }
  },
  mounted() {
    this.getList();
  }
}
</script>

<style scoped>
/* 页面整体样式 */
.mall-wrapper {
  background-color: #f5f5f5;
  min-height: 100vh;
  padding-bottom: 40px;
  box-sizing: border-box;
  overflow: hidden;
  width: 1460px;
  margin: 0 auto;
  padding: 0;
}

.banner-content h2 {
  font-size: 28px;
  margin-bottom: 20px;
}

.banner-content p {
  line-height: 1.6;
  margin-bottom: 30px;
}

.banner-btn {
  padding: 10px 20px;
  background-color: #00AF84;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.banner-btn :hover {
  background-color: #009670;
}

.banner-img img {
  width: 300px;
  height: auto;
}

/* 筛选区域样式 */
.filter {
  display: flex;
  align-items: center;
  margin-left: 90px;
  gap: 10px;
  padding: 20px;
}

.search-input,
.filter-select {
  box-sizing: border-box;
  width: 191.88px;
  height: 40px;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  color: rgba(0, 0, 0, 0.5);
}

.search-input::placeholder {
  color: rgba(0, 0, 0, 0.5);
}

.filter-btn {
  height: 39.6px;
  width: 69.6px;
  padding: 8px 15px;
  background-color: #00AF84;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

/* 功能列表样式 */
.feature-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 70px;
  padding: 20px;
  margin-left: 90px;
}

.feature-item {
  width: 255px;
  height: 270px;
  text-align: center;
  border: 1px solid #eee;
  border-radius: 4px;
  padding: 0px;
  margin: 0;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
}

.item-content {
  display: flex;
  flex-direction: column;
  gap: 0px;
  padding: 0px;
}

/* 标题容器样式 */
.title-container {
  display: flex;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
}

/*图标样式 */
.icon {
  width: 40px;
  height: 40px;
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
}

/* 图片容器 */
.image-container {
  position: relative;
  width: 100%;
  height: 140px;
  overflow: hidden;
}

/* 悬停时放大图片 */
.image-container:hover {
  transform: scale(1.05);
  /* 放大 5% */
  cursor: pointer;
  /* 改变鼠标样式为手型 */
}

.feature-item img {
  height: 140px;
  width: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

/* 悬停时放大图片 */
.image-container:hover img {
  transform: scale(1.1);
}

/* 类型标签 */
.type-label {
  position: absolute;
  bottom: 0px;
  left: 0px;
  background-color: #4CAF50;
  color: white;
  padding: 4px 8px;
  font-size: 12px;
  z-index: 1;
  opacity: 0.8;
  /*类型透明度 */
}

/* 多行文本截断核心样式 */
.desc-truncate {
  margin: 0;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  line-height: 24px;
  max-height: 48px;
  color: #666;
  text-overflow: ellipsis;
  text-align: left;
  font-size: 15px;
  padding-left: 0.5em;
  /* 替代 text-indent */
}

/* 分页样式 */
/* 分页容器 */
/* 分页容器 */
.pagination {
  display: flex;
  justify-content: center;
  padding: 20px;
  margin-top: 20px;
}

.pagination ul {
  list-style: none;
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 0;
}

/* 公共按钮样式 */
.pagination li {
  padding: 6px 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s ease;
}

/* 上一页和下一页按钮 */
.pagination-prev,
.pagination-next {
  background-color: #fff;
  color: #666;
  border-color: #ccc;
}

.pagination-prev:hover,
.pagination-next:hover {
  background-color: #f0f0f0;
}

/* 页码按钮 */
.pagination-page {
  background-color: #fff;
  color: #333;
  border-color: #ccc;
}

.pagination-page.active {
  background-color: #42b983;
  color: white;
  border-color: #42b983;
}
</style>
